import apiMode from '@/apiMod/index'

const booleanDict = [
	{
		label: '允许',
		value: true,
	},
	{
		label: '不允许',
		value: false,
	},
]

export const serviceRuleConfig = [
	{
		label: '服务老人年龄设置',
		prop: 'age',
		type: 'RangeValue',
		isInter: true,
		span: 8,
		rules: [{ required: true, message: '请输入服务老人年龄设置' }],
	},
	{
		label: '服务人员与老人服务距离限制（米）',
		prop: 'distance',
		maxlength: '50',
		showWordLimit: true,
		type: 'text',
		span: 8,
	},

	{
		label: '老人是否允许多家服务组织进行服务',
		prop: 'multiOrgService',
		type: 'radio',
		dicData: [
			{
				label: '否',
				value: false,
			},
			{
				label: '是',
				value: true,
			},
		],
		rules: [{ required: true, message: '请选择老人是否允许多家服务组织进行服务' }],
		span: 8,
	},
	{
		label: '工单服务项目是否允许跨大类选择',
		prop: 'allowMultiSupItem',
		type: 'radio',
		dicData: [
			{
				label: '否',
				value: false,
			},
			{
				label: '是',
				value: true,
			},
		],
		rules: [{ required: true, message: '请选择工单服务项目是否允许跨大类选择' }],
		span: 8,
	},
	{
		label: '工单服务项目最大允许几项（大类）',
		prop: 'maxSupItems',
		type: 'number',
		min: 1,
		step: 1,
		precision: 0,
		controlsPosition: 'right',
		span: 8,
	},

	{
		label: '同一大类下是否允许选择多项(小类)',
		prop: 'allowMultiSubItem',
		type: 'radio',
		dicData: [
			{
				label: '否',
				value: false,
			},
			{
				label: '是',
				value: true,
			},
		],
		span: 8,
	},
	{
		label: '同一大类下最大允许几项（小类）',
		prop: 'maxSubItems',
		span: 8,
		type: 'number',
		min: 1,
		step: 1,
		precision: 0,
		controlsPosition: 'right',
	},
	{
		label: '选择多个不同服务项目小类，工单结束判定规则',
		prop: 'calcEndServiceLength',
		type: 'radio',
		dicData: [
			{
				label: '取最大服务小类时长',
				value: 1,
			},
			{
				label: '取服务小类之和',
				value: 2,
			},
		],
		span: 8,
	},

	{
		label: '是否限制同一老人一天内最高有效工单数(单)',
		prop: 'limitElderlyDayOrder',
		type: 'radio',
		dicData: [
			{
				label: '否',
				value: false,
			},
			{
				label: '是',
				value: true,
			},
		],
		span: 8,
	},
	{
		label: '同一老人一天内最高有效工单数',
		prop: 'limitElderlyDayOrderNum',
		type: 'number',
		min: 1,
		step: 1,
		precision: 0,
		controlsPosition: 'right',
		span: 8,
	},

	{
		label: '老人服务间隔方式',
		prop: 'stepElderlyServiceType',
		type: 'radio',
		dicData: [
			{
				label: '上一单开始时间与下一单开始时间',
				value: 1,
			},
			{
				label: '上一单结束时间与下一单开始时间',
				value: 2,
			},
		],
		span: 12,
	},
	{
		label: '同一老人连续服务时间间隔（分钟）',
		prop: 'stepElderlyServiceLimit',
		type: 'number',
		min: 1,
		step: 1,
		precision: 0,
		controlsPosition: 'right',
		span: 8,
	},

	{
		label: '员工服务间隔方式',
		prop: 'stepStaffServiceType',
		type: 'radio',
		dicData: [
			{
				label: '上一单开始时间与下一单开始时间',
				value: 1,
			},
			{
				label: '上一单结束时间与下一单开始时间',
				value: 2,
			},
		],
		span: 16,
	},
	{
		label: '同一员工连续服务时间间隔（分钟）',
		prop: 'stepStaffServiceLimit',
		type: 'number',
		min: 1,
		step: 1,
		precision: 0,
		controlsPosition: 'right',
		span: 8,
	},
]

export const orderRuleConfig = [
	{
		label: '不再规定时间内是否允许服务',
		prop: 'allowService',
		type: 'radio',
		dicData: [
			{
				label: '允许',
				value: true,
			},
			{
				label: '不允许',
				value: false,
			},
		],
		span: 8,
		rules: [{ required: true, message: '请选择不再规定时间内是否允许服务' }],
	},
	{
		label: '有效服务工单起止时间',
		prop: 'allowServiceBetween',
		type: 'timePicker',
		isRange: true,
		valueFormat: 'HH:mm:ss',
		span: 8,
		rules: [{ required: true, message: '请选择有效服务工单起止时间' }],
	},
	{
		label: '工单服务时长（大于>?分钟）判定异常',
		prop: 'maxServiceLength',
		type: 'number',
		min: 1,
		step: 1,
		precision: 0,
		controlsPosition: 'right',
		span: 8,
	},
	{
		label: '在失能险老人的开始时间及结束时间期间是否允许享受服务',
		prop: 'allowSpecialDisabilityService',
		type: 'radio',
		dicData: booleanDict,
		span: 8,
	},
	{
		label: '在机构老人的开始时间及结束时间期间是否允许享受服务',
		prop: 'allowSpecialOrgService',
		type: 'radio',
		dicData: booleanDict,
		span: 8,
	},
	{
		label: '在家床老人的开始时间及结束时间期间是否允许享受服务',
		prop: 'allowSpecialBedService',
		type: 'radio',
		dicData: booleanDict,
		span: 8,
	},
	{
		label: '在援助老人的开始时间及结束时间期间是否允许享受服务',
		prop: 'allowSpecialAidService',
		type: 'radio',
		dicData: booleanDict,
		span: 8,
	},
	{
		label: '在老干部老人的开始时间及结束时间期间是否允许享受服务',
		prop: 'allowSpecialCadreService',
		type: 'radio',
		dicData: booleanDict,
		span: 8,
	},
	// {
	// 	label: '在失能险、机构、家床、援助、老干部的开始时间及结束时间期间是否允许享受政府购买照护服务',
	// 	prop: 'allowCareService',
	// 	type: 'radio',
	// 	dicData: [
	// 		{
	// 			label: '允许',
	// 			value: true,
	// 		},
	// 		{
	// 			label: '不允许',
	// 			value: false,
	// 		},
	// 	],
	// 	span: 16,
	// },

	{
		label: '不再规定时间内是否允许助餐',
		prop: 'allowHelpFood',
		type: 'radio',
		dicData: [
			{
				label: '允许',
				value: true,
			},
			{
				label: '不允许',
				value: false,
			},
		],
		span: 8,
	},
	{
		label: '有效助餐时间-早餐',
		prop: 'breakfastBetween',
		type: 'timePicker',
		isRange: true,
		valueFormat: 'HH:mm:ss',
		span: 8,
	},
	{
		label: '有效助餐时间-中餐',
		prop: 'lunchBetween',
		type: 'timePicker',
		isRange: true,
		valueFormat: 'HH:mm:ss',
		span: 8,
	},
	{
		label: '有效助餐时间-晚餐',
		prop: 'dinnerBetween',
		type: 'timePicker',
		valueFormat: 'HH:mm:ss',
		isRange: true,
		span: 8,
	},

	{
		label: '每日早中晚助餐服务是否认定第一条为有效工单',
		prop: 'helpFoodValidFirst',
		type: 'radio',
		dicData: [
			{
				label: '否',
				value: false,
			},
			{
				label: '是',
				value: true,
			},
		],
		span: 8,
	},
]

export const serviceIngRuleConfig = [
	{
		label: '创建服务工单时是否要求识别员工人脸',
		prop: 'startStaffFace',
		type: 'radio',
		dicData: [
			{
				label: '否',
				value: false,
			},
			{
				label: '是',
				value: true,
			},
		],
		rules: [{ required: true, message: '请选择创建服务工单时是否要求识别员工人脸' }],
		span: 12,
	},
	{
		label: '创建服务工单时是否要求识别老人人脸',
		prop: 'startElderlyFace',
		type: 'radio',
		dicData: [
			{
				label: '否',
				value: false,
			},
			{
				label: '是',
				value: true,
			},
		],
		rules: [{ required: true, message: '请选择创建服务工单时是否要求识别老人人脸' }],
		span: 12,
	},
	{
		label: '结束服务工单时是否要求识别员工人脸',
		prop: 'endStaffFace',
		type: 'radio',
		dicData: [
			{
				label: '否',
				value: false,
			},
			{
				label: '是',
				value: true,
			},
		],
		rules: [{ required: true, message: '请选择结束服务工单时是否要求识别员工人脸' }],
		span: 12,
	},
	{
		label: '结束服务工单时是否要求识别老人人脸',
		prop: 'endElderlyFace',
		type: 'radio',
		dicData: [
			{
				label: '否',
				value: false,
			},
			{
				label: '是',
				value: true,
			},
		],
		rules: [{ required: true, message: '请选择结束服务工单时是否要求识别老人人脸' }],
		span: 12,
	},
	{
		label: '服务前照片是否要求必传',
		prop: 'beforeServicePicRequired',
		type: 'radio',
		dicData: [
			{
				label: '否',
				value: false,
			},
			{
				label: '是',
				value: true,
			},
		],
		rules: [{ required: true, message: '请选择服务前照片是否要求必传' }],
		span: 12,
	},
	{
		label: '服务前照片最大上传数量(张)',
		prop: 'beforeServicePicNum',
		type: 'number',
		min: 1,
		step: 1,
		precision: 0,
		controlsPosition: 'right',
		span: 12,
	},
	{
		label: '服务中照片是否要求必传',
		prop: 'middleServicePicRequired',
		type: 'radio',
		dicData: [
			{
				label: '否',
				value: false,
			},
			{
				label: '是',
				value: true,
			},
		],
		rules: [{ required: true, message: '请选择服务中照片是否要求必传' }],
		span: 12,
	},
	{
		label: '服务中照片最大上传数量(张)',
		prop: 'middleServicePicNum',
		type: 'number',
		min: 1,
		step: 1,
		precision: 0,
		controlsPosition: 'right',
		span: 12,
	},

	{
		label: '服务后照片是否要求必传',
		prop: 'afterServicePicRequired',
		type: 'radio',
		dicData: [
			{
				label: '否',
				value: false,
			},
			{
				label: '是',
				value: true,
			},
		],
		rules: [{ required: true, message: '请选择服务后照片是否要求必传' }],
		span: 12,
	},
	{
		label: '服务后照片最大上传数量(张)',
		prop: 'afterServicePicNum',
		type: 'number',
		min: 1,
		step: 1,
		precision: 0,
		controlsPosition: 'right',
		span: 12,
	},
	{
		label: '服务中是否随机录音',
		prop: 'allowRadio',
		type: 'radio',
		dicData: [
			{
				label: '否',
				value: false,
			},
			{
				label: '是',
				value: true,
			},
		],
		span: 12,
	},
	{
		label: '服务开始后指定时间开启录音',
		prop: 'allowRadioStartMin',
		type: 'number',
		min: 1,
		step: 1,
		precision: 0,
		controlsPosition: 'right',
		span: 12,
	},
]
export const ruleSetConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	inlineMessage: true,
	column: [
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '服务规则',
			custome: 'divider',
			span: 24,
		},
		...serviceRuleConfig,
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '工单规则',
			span: 24,
			custome: 'divider',
		},
		...orderRuleConfig,
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '服务过程规则',
			span: 24,
			custome: 'divider',
		},
		...serviceIngRuleConfig,
	],
}

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'left',
	labelWidth: '120px',
	column: [
		{
			label: '规则名称',
			prop: 'ruleName',
			type: 'input',
			span: 24,
			rules: [{ required: true, message: '请输入规则名称' }],
		},
		{
			label: '规则配置',
			prop: 'ruleConfig',
			type: 'input',
			span: 24,
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '规则名称',
			prop: 'ruleName',
			type: 'input',
			span: 8,
		},
		{
			label: '启用状态',
			prop: 'ruleStatus',
			type: 'select',
			dicData: [
				{ label: '启用', value: 1 },
				{ label: '停用', value: 0 },
			],
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		// { label: '项目名称', prop: 'projectName' },
		{ label: '规则名称', prop: 'ruleName' },
		{
			label: '规则启用状态',
			prop: 'ruleStatus',
		},
		{ label: '创建人', prop: 'createUserName' },
		{ label: '创建时间', prop: 'createTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_omProjectRule_page',
	add: 'view_omProjectRule_add',
	edit: 'view_omProjectRule_edit',
	delete: 'view_omProjectRule_del',
	detail: 'view_omProjectRule_one',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '项目规则设置',
	dictcodes: [],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'ruleName',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],
	operateFormate: (row, type) => {
		return new Promise((resolve, reject) => {
			if ((type == 'edit' || type == 'delete') && row.ruleStatus == 1) {
				ElMessage.warning('该规则已启用，请先停用后再操作!')
				return
			}
			if (row.id) {
				apiMode[api.detail]({ id: row.id }).then((res) => {
					let ruleConfig = res.data.ruleConfig
					if (ruleConfig && typeof ruleConfig != 'string') {
						ruleConfig = {
							...ruleConfig.orderRule,
							...ruleConfig.processRule,
							...ruleConfig.serviceRule,
						}
					}

					ruleConfig.allowServiceBetween = ruleConfig.allowServiceBetween ? ruleConfig.allowServiceBetween?.split(',') : []
					ruleConfig.breakfastBetween = ruleConfig.breakfastBetween ? ruleConfig.breakfastBetween?.split(',') : []
					ruleConfig.dinnerBetween = ruleConfig.dinnerBetween ? ruleConfig.dinnerBetween?.split(',') : []
					ruleConfig.lunchBetween = ruleConfig.lunchBetween ? ruleConfig.lunchBetween?.split(',') : []

					let form: any = {
						...row,
						ruleConfig,
					}
					if (type == 'detail') {
						form = {
							...row,
							...ruleConfig,
						}
					}
					resolve(form)
				})
				return
			}
			resolve(row)
		})
	},
	dialogConfig: {
		width: '75%',
	},
	searchConfig,
	formConfig,
	tableConfig,
	detailConfig: ruleSetConfig,
}
